<?php
chdir('../../');
include ('includes/application_top.php');
include ('includes/modules/payment/qpay.php');

if(isset($_POST))
{
    $paymentState = '';
    $order_id = isset($_POST['order_id']) ? htmlentities($_POST['order_id']) : '';
    $q = xtc_db_query('SELECT qpay_response FROM ' . TABLE_PAYMENT_QPAY . ' WHERE orders_id = "'.$order_id.'" LIMIT 1;');
    if(xtc_db_num_rows($q))
    {
        $dbEntry = xtc_db_fetch_array($q);
        $paymentInformation = unserialize($dbEntry['qpay_response']);
        $paymentState = $paymentInformation['paymentState'];
    }

    switch ($paymentState)
    {
        case 'SUCCESS':
            $link = xtc_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL');
            break;
        case 'CANCEL':
            $link = xtc_href_link('checkout_qpay.php', 'cancel=1', 'SSL');
            break;
        default:
            $link = xtc_href_link('checkout_qpay.php', 'failure=1', 'SSL');
            break;
    }
}
?>
<html>
<head>
</head>
<body onLoad="window.parent.location.href = '<?php echo $link; ?>'">
</body>
</html>